<template>
    <view class="box_1">
        <view class="business-record">
            <view class="top_bak">
                <view class="top_group_1">
                    <view class="ware_top_1">
                        <view class="top_group_1_1">
                            <view class="group_ticket_1_text">{{storage_ticket}}</view>
                        </view>
                        <view class="group_ticket_2_text">仓储券总额</view>
                    </view>
                    <view class="group_ticket_2_text_1" @tap="goGroupRule()">规则</view>
                </view>
            </view>
            <view class="r-data">
                <view class="top_1_box">
                    <view  @tap="hanldeShowData1()"><image class="date_image" src="../../static/img/cash_date.png"></image></view>
                    <view class="d-time" @tap="hanldeShowData1()">{{show_start_time}}</view>
                    <!--                    <view @tap="hanldeShowData1()"><image  class="date_image_2" src="../../static/img/sale_arrow_2.png"/></view>-->
                    <view class="top_2_box"  @tap="hanldeShowData2()"><image class="date_image" src="../../static/img/cash_date.png"></image></view>
                    <view class="d-time" @tap="hanldeShowData2()">{{show_end_time}}</view>

                    <view class="group_button_1">
                        <button class="group_button" @tap="clear()">清除</button>
                    </view>
                    <view class="group_button_2">
                        <button class="group_button" @tap="goSearch()">搜索</button>
                    </view>
                </view>
            </view>
            <view class="r-list">
                <view v-if="businessList.length===0">
                    <mNodata></mNodata>
                </view>
                <view  v-else class="l-box" v-for="(item,index) in businessList" :key="index">
                    <view class="b-num">
                        <view class="n-title">交易类型:&nbsp{{item.type_name}}</view>
                        <view class="n-money">
                            <view v-if="item.add_type===0" class="n-money-text">-{{item.price}}</view>
                            <view v-if="item.add_type===1" class="n-money-text_1">+{{item.price}}</view>
                        </view>
                    </view>
                    <view class="b-time">
                        <view class="t-title">{{item.created_at}}</view>
                    </view>
                </view>
            </view>
        </view>
        <!--        <van-calendar-->
        <!--                type="single"-->
        <!--                :min-date="minDate"-->
        <!--                :max-date="maxDate"-->
        <!--                :show="beginShowData"-->
        <!--                :default-date="defaultDate"-->
        <!--                :title="'选择开始日期'"-->
        <!--                :close-on-click-overlay="true"-->
        <!--                @close="handleCloseData1"-->
        <!--                @confirm="handleSubmitData1"-->
        <!--        />-->
        <!--        <van-calendar-->
        <!--                type="single"-->
        <!--                :min-date="minDate"-->
        <!--                :max-date="maxDate"-->
        <!--                :show="endShowData"-->
        <!--                :default-date="defaultDate"-->
        <!--                :title="'选择结束日期'"-->
        <!--                :close-on-click-overlay="true"-->
        <!--                @close="handleCloseData2"-->
        <!--                @confirm="handleSubmitData2"-->
        <!--        />-->
        <van-popup :show="beginShowData" position="bottom" :overlay="true"  @close="onClose($event)"
                   @touchmove.stop.prevent="moveHandle"
        >
            <van-datetime-picker
                    type="date"
                    title="选择开始日期"
                    :value="currentDate"
                    @cancel="handleCloseData1"
                    @confirm="handleSubmitData1"
            />
        </van-popup>


        <van-popup :show="endShowData" position="bottom" :overlay="true"  @close="onClose($event)"
                   @touchmove.stop.prevent="moveHandle"
        >
            <van-datetime-picker
                    type="date"
                    title="选择结束日期"
                    :value="currentDate"
                    @cancel="handleCloseData2"
                    @confirm="handleSubmitData2"
            />
        </van-popup>

    </view>
</template>

<script>
    export default {
        name: "wareHouseTicketLog",
        data() {
            return {
                businessList:[],
                beginShowData:false,
                endShowData:false,
                // minDate: new Date(2020, 0, 1).getTime(),
                maxDate: new Date().getTime(),
                defaultDate:new Date().getTime(),
                start_time:'',
                end_time:'',
                show_start_time:'开始日期',
                show_end_time:'结束日期',
                page:1,
                is_load:0,
                currentDate: new Date().getTime(),
                select_show:false,
                group_wallet_money:'0.00',
                storage_ticket:'0.00'
            }
        },
        onShow() {
            this.page=1
            this.is_load=0
            this.businessList=[]
            this.getBuyLog()
        },
        onReachBottom() {  //分页加载请求数据
            if(this.is_load>0){
                this.page++
                this.getBuyLog()
            }else{
                uni.showToast({
                    title:"没有更多数据啦",
                    icon:"none",
                    duration:3000
                })
            }
        },
        methods: {
            onConfirm(event){ //选择器确认
                const { picker, value, index } = event.detail;
                let date=this.timestampToTime(event.detail)
                console.log(date)
                this.select_show=false
            },
            timestampToTime (cjsj) {
                let date = new Date(cjsj) //时间戳为10位需*1000，时间戳为13位的话不需乘1000
                let Y = date.getFullYear() + '-'
                let M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-'
                let D = date.getDate() + ' '
                return Y+M+D
            },
            onCancel(event){  //选择器取消
                this.select_show=false
            },
            onClose(event) { // 遮罩关闭
                this.select_show=false
            },
            moveHandle () {},
            //展示日期
            hanldeShowData1(res){
                this.beginShowData=true
                this.select_show=true
            },
            hanldeShowData2(res){
                this.endShowData=true
                this.select_show=true
            },

            //关闭日期弹窗
            handleCloseData1(res){
                this.beginShowData=false
            },
            //关闭结束日期弹窗
            handleCloseData2(res){
                this.endShowData=false
            },
            //选择开始日期完成后
            handleSubmitData1(res){
                // let year=res.detail.getFullYear()
                // let month=res.detail.getMonth()+1
                // let day=res.detail.getDate()
                // this.start_time=year+'-'+month+'-'+day
                this.start_time=this.timestampToTime(res.detail)
                this.show_start_time=this.start_time
                this.beginShowData=false
                // this.page=1
                // this.is_load=0
                // this.businessList=[]
                // this.getBuyLog()
            },

            //选择结束日期完成后
            handleSubmitData2(res){
                // let year=res.detail.getFullYear()
                // let month=res.detail.getMonth()+1
                // let day=res.detail.getDate()
                // this.end_time=year+'-'+month+'-'+day
                this.end_time=this.timestampToTime(res.detail)
                this.show_end_time=this.end_time
                this.endShowData=false
            },
            //获取列表
            async getBuyLog(){
                uni.showLoading({})
                let resData =await this.$apis.getStorageLog({
                    access_token: '',
                    page:this.page,
                    start_time:this.start_time,
                    end_time:this.end_time
                })
                if(resData.code===0){
                    this.businessList.push(...resData.data.lists)
                    this.is_load=resData.data.is_load
                    this.storage_ticket=resData.data.storage_ticket
                }
                uni.hideLoading()
            },
            goNeedGroup(){
                // uni.navigateTo({
                //     url: "../user/needGetGroup"
                // })
                this.$router.push({
                    route:this.$routesConfig.needGetGroup,
                })
            },
            goGroupRule(){
                uni.navigateTo({
                    url: "../user/storageRule"
                })
            },
            clear(){ //点击清除
                this.start_time=''
                this.end_time=''
                this.show_start_time='开始日期'
                this.show_end_time='结束日期'
            },
            //点击搜索
            goSearch(){
                if((this.start_time==='' && this.end_time==='') || (this.start_time!=='' && this.end_time!=='')){
                    this.page=1
                    this.is_load=0
                    this.businessList=[]
                    this.getBuyLog()
                }else{
                    uni.showToast({
                        title:"请将时间范围选择完整",
                        icon:"none",
                        duration:3000
                    })
                }
            }
        },
    }
</script>
<style>
    page {
        background-color:#FAFAFA
    }
</style>
<style lang="less" scoped>
    .business-record{
        background-color: #ffffff;
        position: relative;
        width: 100%;
        /*margin-left: 50rpx;*/
        .r-data{
            /*position: fixed;*/
            background-color: #ffffff;
            width: 100%;
            height: 80rpx;
            display: flex;
            box-sizing: border-box;
            padding: 0 30rpx;
            justify-content: space-between;
            align-items: center;
            border-bottom: solid 1px #EDEDED;
            .d-time{
                font-size: 23rpx;
                color: #999999;
                margin-left: 10rpx;
                width: 130rpx;
                margin-top: 9rpx;
                line-height: 1.5;


            }
            .date_arrow_image{
                position: relative;
                width: 40rpx;
                height: 40rpx;
                /*margin-left: -120rpx;*/
            }
        }
        .r-list{
            width: 100%;
            box-sizing: border-box;
            padding: 0rpx 20rpx 0 20rpx;
            .l-box{
                box-sizing: border-box;
                border-bottom: solid 1px #EDEDED;
                padding: 40rpx 0;
                .b-num{
                    display: flex;
                    justify-content: space-between;
                    // line-height: 80rpx;
                    .n-title{
                        font-size: 26rpx;
                        color: #333333;

                    }
                    .n-money{
                        font-size: 26rpx;
                        color: #333333;
                        text-align: right;

                    }
                }
                .b-time{
                    padding-top: 20rpx;
                    display: flex;
                    justify-content: space-between;
                    // line-height: 80rpx;
                    .t-title{
                        font-size: 24rpx;
                        color: gray;
                    }
                    .t-status{
                        font-size: 24rpx;
                        color:#999999;
                    }
                }
            }
        }
    }
    .business_number{
        display: flex;
        flex-direction: row;
        width: 226rpx;
        /*border: solid 0.5px #999999;*/
        border-radius: 10px;
        font-size: 25rpx;
        margin-right: -9px;
    }
    .search_image{
        margin-top: 7rpx;
        height: 35rpx;
        width: 35rpx;
    }
    .date_image{
        /*margin-left: 12rpx;*/
        height: 40rpx;
        width: 40rpx;
    }
    .date_image_2{
        /*margin-left: 12rpx;*/
        height: 17rpx;
        width: 30rpx;
        transform:  translate(0,20%);
        /*margin-left: 10rpx;*/
    }
    .empty_img{
        margin-top: 200rpx;
        width: 520rpx;
        height: 360rpx;
    }
    .empty_text{
        color: #333333;
        font-size: 26rpx;
        margin-top: 20rpx;
    }
    .empty_box{
        text-align: center;
    }
    .button_1{
        width: 108rpx;
        border: none;
        background-color: #FF9502;
        font-size:26rpx;
        color: #ffffff;
    }
    .button_1:nth-child(1){
        margin-right: 10rpx;
    }
    .total_cash{
        font-size: 26rpx;
        color: #F19317;
    }
    .top_1_box{
        display: flex;
        flex-direction: row;
        /*margin-left: 40%;*/
    }
    .watch_all{
        margin-left: 20rpx;
        font-size: 25rpx;
        color: #333333;
        margin-top: 9rpx;
    }
    .n-money-text{
        margin-top: 20rpx;
        font-size: 30rpx;
        color:green;
    }
    .n-money-text_1{
        margin-top: 20rpx;
        font-size: 30rpx;
        color:red;
    }
    .select_box{
        position: fixed;
        bottom: 0;
    }
    .top_bak{
        background-image: url("https://qiniu.scxhrd.com/static/img/ware_house.png");
        background-size: 100%;
        background-repeat: no-repeat;
        width: 95%;
        height: 280rpx;
        margin-left: 2.5%;
    }
    .top_2_box{
        margin-left: 40rpx;
    }
    .group_button{
        width: 110rpx;
        height: 50rpx;
        background-color: #FF9502;
        font-size: 25rpx;
        color:#ffffff;
        line-height: 2;
    }
    .group_button_2{
        margin-left: 20rpx;
    }
    .group_button_1{
        margin-left: 30rpx;
        margin-right:20rpx ;
    }
    .top_group_1{
        display: flex;
        justify-content: space-around;
        padding-top: 55rpx;
    }
    .top_group_1_1{
        display: flex;
        justify-content: space-around;
    }
    .group_button_3{
        width: 150rpx;
        height: 50rpx;
        background-color: #FF6576;
        font-size: 26rpx;
        color:#ffffff;
        line-height: 2;
        margin-left: 20rpx;
    }
    .group_ticket_1_text{
        color: #ffffff;
        font-size: 40rpx;
        text-align: center;
        /*margin-left: 20rpx;*/
    }
    .group_ticket_2_text{
        color: #ffffff;
        font-size: 28rpx;
        margin-top: 20rpx;
        text-align: center;
    }
    .group_ticket_2_text_1{
        color: #ffffff;
        font-size: 50rpx;
        margin-top: 20rpx;
        margin-right: -45rpx;
    }
    .group_ticket_3_text{
        color: #ffffff;
        font-size: 35rpx;
    }
    .group_button_3::after{
        border:1px solid transparent;
    }
    .group_button_1::after{
        border:1px solid transparent;
    }
    .group_button_2::after{
        border:1px solid transparent;
    }
    .group_button::after{
        border:1px solid transparent;
    }
    .ware_top_1{
        margin-left: 50rpx;
    }
</style>
